<template>
  <div class="paper-table-container">
    <!-- 查询条件区域 -->
    <el-form :inline="true" :model="searchForm" class="search-form">
      <el-form-item label="题目ID">
        <el-input v-model="searchForm.id" placeholder="请输入题目ID"></el-input>
      </el-form-item>
     <el-form-item label="年级:">
        <el-select v-model="formInline.level" placeholder="年级" size="large" style="width: 180px">
          <el-option v-for="item in levelStore.list" :key="item.value" :label="item.name" :value="item.value"></el-option>
          <!-- 可扩展更多年级选项 -->
        </el-select>
      </el-form-item>
      <el-form-item label="学科">
        <el-select v-model="searchForm.subject" placeholder="请选择" style="width: 180px">
          <el-option label="数学" value="数学"></el-option>
          <el-option label="化学" value="化学"></el-option>
          <el-option label="语文" value="语文"></el-option>
          <!-- 可扩展更多学科选项 -->
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSearch">查询</el-button>
        <el-button type="primary" @click="handleAdd">添加</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格区域 -->
    <el-table :data="tableData" border style="width: 100%" class="paper-table">
      <el-table-column prop="id" label="Id"></el-table-column>
      <el-table-column prop="subject" label="学科"></el-table-column>
      <el-table-column prop="name" label="名称"></el-table-column>
      <el-table-column prop="createTime" label="创建时间"></el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button type="primary" size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页区域 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
    ></el-pagination>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'
import { useLevelStore } from '@/stores/level'
// Vue 3 中按需引入 Element Plus 组件（也可全局引入，看项目配置）
import { ElForm, ElFormItem, ElInput, ElSelect, ElOption, ElButton, ElTable, ElTableColumn, ElPagination } from 'element-plus'

// 搜索表单数据
const searchForm = reactive({
  id: '',
  grade: '',
  subject: ''
})
const formInline = ref({
  level: '',
  pageIndex: 1,
  pageSize: 10
})
const levelStore =useLevelStore()
// 表格数据（模拟，实际可从接口获取）
const tableData = ref([
  { id: 66, subject: '数学（高三）', name: '高三数据任务试卷', createTime: '2024-12-25 06:54:22' },
  { id: 65, subject: '化学（一年级）', name: '12', createTime: '2024-12-25 06:53:57' },
  // ... 其他模拟数据，与截图一致
])
// 分页相关
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(60)

// 查询事件
const handleSearch = () => {
  console.log('查询条件：', searchForm)
  // 实际可调用接口，根据 searchForm 传参获取表格数据，更新 tableData、total 等
}
// 添加事件
const handleAdd = () => {
  console.log('点击添加')
  // 可跳转添加页面或弹出添加弹窗
}
// 编辑事件
const handleEdit = (row) => {
  console.log('编辑行数据：', row)
  // 可跳转编辑页面或弹出编辑弹窗，携带 row 数据
}
// 删除事件
const handleDelete = (row) => {
  console.log('删除行数据：', row)
  // 可调用接口删除，再更新 tableData
}
// 每页条数改变
const handleSizeChange = (val) => {
  pageSize.value = val
  // 调用接口重新获取数据，更新 tableData
}
// 当前页改变
const handleCurrentChange = (val) => {
  currentPage.value = val
  // 调用接口重新获取数据，更新 tableData
}
</script>

<style scoped>
.paper-table-container {
  padding: 20px;
}
.search-form {
  margin-bottom: 16px;
}
.paper-table {
  margin-bottom: 16px;
}
.pagination {
  text-align: right;
}


</style>